<template>
    <!-- pages/getBalance/getBalance.wxml -->
    <view class="container">
        <!-- 账户金额 -->
        <!-- <view class="account">
    <view class="item">总通用余额:<text>{{userinfo.balance}}</text>元</view>
    <view class="item">总赠送余额:<text>{{userinfo.giftBalance}}</text>元</view>
  </view> -->
        <view class="head">
            <view class="cell1">门店名称</view>
            <view class="cell2">账户余额</view>
            <view class="cell2">赠送余额</view>
        </view>
        <view class="list">
            <block v-if="MainList.length > 0">
                <view class="item" v-for="(item, index) in MainList" :key="index">
                    <view class="name">{{ item.storeName }}</view>

                    <view class="price">
                        <text class="color-attention">{{ item.balance }}</text>
                    </view>

                    元

                    <view class="price">
                        <text class="color-attention">{{ item.giftBalance }}</text>
                    </view>

                    元
                </view>
            </block>
            <block v-else>
                <view class="nodata">暂无数据</view>
            </block>
        </view>
    </view>
</template>

<script>
// pages/getBalance/getBalance.js
var http = require('../../utils/http');
var util1 = require('../../utils/util.js');
const app = getApp();
export default {
    data() {
        return {
            userinfo: {},
            //用户信息
            MainList: [] //列表数组
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad(options) {},
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        // this.getuserinfo();
        this.getData();
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {
        // this.getuserinfo();
        this.getData();
    },
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {},
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {},
    methods: {
        getuserinfo: function () {
            var that = this;
            if (app.globalData.isLogin) {
                http.request(
                    '/member/user/get',
                    '1',
                    'get',
                    {},
                    app.globalData.userDatatoken.accessToken,
                    '',
                    function success(info) {
                        console.info('我的信息===');
                        console.info(info);
                        if (info.code == 0) {
                            that.setData({
                                userinfo: info.data
                            });
                        }
                    },
                    function fail(info) {}
                );
            } else {
                //console.log('未登录失败！')
            }
        },

        //获取列表数据
        getData: function () {
            var that = this;
            if (app.globalData.isLogin) {
                http.request(
                    '/member/user/getGiftBalanceList',
                    '1',
                    'get',
                    {},
                    app.globalData.userDatatoken.accessToken,
                    '',
                    function success(info) {
                        console.info('我的信息===');
                        console.info(info);
                        if (info.code == 0) {
                            that.setData({
                                MainList: info.data
                            });
                        }
                    },
                    function fail(info) {}
                );
            } else {
                //console.log('未登录失败！')
            }
        }
    }
};
</script>
<style>
@import './getBalance.css';
</style>
